using System;
using System.Collections.Generic;
using System.Reflection;
using HCP.SimpleJSON;

namespace HCP
{
	public abstract class JobResponse : JSONClass
	{
		protected JobResponse(string data)
		{
			this.Status = JobResponse.EStatus.Success;
			this.Content = data;
		}

		protected JobResponse(object data)
		{
			this.Status = JobResponse.EStatus.Success;
			JSONClass jsonclass = new JSONClass();
			Type type = data.GetType();
			IList<PropertyInfo> list = new List<PropertyInfo>(type.GetProperties());
			foreach (PropertyInfo propertyInfo in list)
			{
				jsonclass.Add(propertyInfo.Name, propertyInfo.GetValue(data, null).ToString());
			}
			this.Content = jsonclass;
		}

		protected JobResponse(object[] data, ArrayEntryFormatter builder)
		{
			this.Status = JobResponse.EStatus.Success;
			JSONArray jsonarray = new JSONArray();
			foreach (object obj in data)
			{
				object obj2 = obj;
				if (builder != null)
				{
					obj2 = builder(obj);
				}
				Type type = obj2.GetType();
				IList<PropertyInfo> list = new List<PropertyInfo>(type.GetProperties());
				JSONClass jsonclass = new JSONClass();
				foreach (PropertyInfo propertyInfo in list)
				{
					jsonclass.Add(propertyInfo.Name, propertyInfo.GetValue(obj2, null).ToString());
				}
				jsonarray.Add(jsonclass);
			}
			this.Content = jsonarray;
		}

		protected JobResponse(JSONClass data)
		{
			this.Status = JobResponse.EStatus.Success;
			this.Content = data;
		}

		public JobResponse.EStatus Status
		{
			get
			{
				return (JobResponse.EStatus)this["status"].AsInt;
			}
			set
			{
				this["status"] = string.Format("{0}", (int)value);
			}
		}

		public JSONNode Content
		{
			get
			{
				return this["value"].AsObject;
			}
			set
			{
				this["value"] = value;
			}
		}

		protected JSONClass m_value;

		public enum EStatus
		{
			Success,
			IndexOutOfBounds,
			NoCollection,
			NoString,
			NoStringLength,
			NoStringWrapper,
			NoSuchDriver,
			NoSuchElement,
			NoSuchFrame,
			UnknownCommand,
			ObsoleteElement,
			ElementNotDisplayed,
			InvalidElementState,
			UnhandledError,
			ExpectedError,
			ElementNotSelectable,
			NoSuchDocument,
			UnexpectedJavaScriptError,
			NoScriptResult,
			XPathLookupError,
			NoSuchCollection,
			Timeout,
			NullPointer,
			NoSuchWindow,
			InvalidCookieDomain,
			UnableToSetCookie,
			UnexpectedAlertOpen,
			NoAlertPresent,
			AsyncScriptTimeout,
			InvalidElementCoordinates,
			InvalidSelector = 32
		}
	}
}
